#include "md_atv.h"
#include "ui_md_atv.h"



Md_atv::Md_atv(TCL_MSTAR_ATV_TV *mstar_atv,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Md_atv)
{
    ui->setupUi(this);
    ms_atv=mstar_atv;
    Q_CHECK_PTR(mstar_atv);
    mstar_atv->Get_Data(&ch_data);
    solution=1;
    My_Init();
}

Md_atv::Md_atv(TCL_MTK_ATV_TV *mtk_atv,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Md_atv)
{
    ui->setupUi(this);
    mt_atv=mtk_atv;
    Q_CHECK_PTR(mtk_atv);
    mtk_atv->Get_Data(&ch_data);
    solution=0;
    My_Init();

}
Md_atv::~Md_atv()
{
    delete ui;
}

bool Md_atv::Is_Close()
{
    if(is_close)
        return true;
    else
        return false;
}

void Md_atv::Set_Close()
{
    is_close=true;
}

void Md_atv::My_Init()
{
    connect(ui->pB_Modify,SIGNAL(clicked()),this,SLOT(Confirm()));
    ui->label->setText("Channel Number:");
    ui->Item1->setText(ch_data.at(0));
    ui->label_2->setText("Channel Name:");
    ui->Item2->setText(ch_data.at(1));
    ui->Item3->setEnabled(false);
    ui->label_3->setText("Channel　Class:");
    ui->Item3->setText(ch_data.at(2));
    ui->label_4->setText("Farvorite Flag:");
    ui->Item4->setText(ch_data.at(3));
    ui->label_5->setText("Skip Flag:");
    ui->Item5->setText(ch_data.at(4));
     is_close=false;
    // connect(this,SIGNAL(Close()),this,SLOT(Set_Close()));
}


//void Md_atv::Close(TCL_MTK_ATV_TV * mt_atv,TCL_MSTAR_ATV_TV *ms_atv)
//{

//}



void Md_atv::Confirm()
{
    ch_data.clear();
    ch_data.append(ui->Item1->text());
    ch_data.append(ui->Item2->text());
    QString tmp;
    tmp.setNum(65);
    ch_data.append(tmp);
    ch_data.append(ui->Item4->text());
    ch_data.append(ui->Item5->text());
    if(1==solution)
    {
        ms_atv->Set_Data(ch_data);
        emit Mstar_Close(*ms_atv);

    }
    else if(0==solution)
    {
        mt_atv->Set_Data(ch_data);
        emit Mtk_Close(*mt_atv);
    }

    this->close();


}
